<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <form class="layui-form layuimini-form" lay-filter="edit-form">
        <input name=id value="" type="hidden" />
        <div class="layui-form-item">
            <label class="layui-form-label required">图标名称</label>
            <div class="layui-input-block">
                <input type="text" name="iconName" autocomplete="off" lay-verify="required" lay-reqtext="图标名称不能为空"
                    placeholder="请输入图标名称" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">图标样式</label>
            <div class="layui-input-block">
                <input type="text" name="iconCss" autocomplete="off" lay-verify="required" lay-reqtext="图标样式不能为空"
                    placeholder="请输入图标样式" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序值</label>
            <div class="layui-input-block">
                <input type="number" name="sort" autocomplete="off" placeholder="请输入排序值" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remarks" autocomplete="off" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="saveBtn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                <button type="reset" class="layui-btn layui-btn-danger">重置</button>
                <input type="button" class="layui-btn layui-btn-primary goback" value="返回"/>
            </div>
        </div>
    </form>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script>
        function initView(obj) {
            console.log(obj);
            var findOneUrl = "/dicms/api/desktop/sys_icon/findOne";
            var saveOneUrl = "/dicms/api/desktop/sys_icon/save";
            layui.use(['form','common'], function () {
                var form = layui.form,
                    layer = layui.layer,
                    common = layui.common,
                    $ = layui.$;
                if (parent.tableConfig.editMode == 0) {

                } else if (parent.tableConfig.editMode == 1) {
                    console.log(obj.data);
                    let objId = obj.data.id;
                    $.ajax({
                        url: findOneUrl,
                        data: { id: objId },
                        type: 'get',
                        dataType: 'json',
                        success: function (res) {
                            console.log(res);
                            if (res.code !== 0) {
                                layer.msg(res.msg, function () {
                                });
                            } else {
                                form.val('edit-form', res.data);
                            }
                        },
                        error: function (res) {
                            console.log(res);
                        }
                    });

                }

                //监听提交
                form.on('submit(saveBtn)', function (data) {
                   
                    data = data.field;
                    console.log(data);
                    if (data.iconName.length > 10) {
                        layer.msg('图标名称太长!');
                        return false;
                    }
                    $("#saveBtn").attr('disabled','disabled');
                    $("#saveBtn").addClass("layui-btn-disabled");
                    $.ajax({
                        url: saveOneUrl,
                        data: data,
                        type: 'post',
                        dataType: 'json',
                        success: function (res) {
                            console.log(res);
                            if (res.code !== 0) {
                                layer.msg(res.msg, function () {
                                });
                            } else {
                                common.refreshAndClose();
                            }
                        },
                        error: function (res) {
                            console.log(res);
                            $("#saveBtn").removeAttr('disabled');
                            $("#saveBtn").removeClass("layui-btn-disabled");
                        }
                    });
                    return false;
                });

                $(".goback").click(function (e) {
                    common.closeIframe();
                });

            });
        }
    </script>
</body>

</html>